﻿namespace Vdc.Grid.Design
{
    using Vdc.Grid;
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Globalization;

    internal class GridCssSettingsConverter : ExpandableObjectConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType));
        }

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                string str = (string) value;
                try
                {
                    string[] strArray = str.Split(new char[] { ',' });
                    GridCssSettings settings = new GridCssSettings();
                    int num = 0;
                    settings.CSSActionLink = strArray[num++].Trim();
                    settings.CSSActionLinkFooter = strArray[num++].Trim();
                    settings.CSSBody = strArray[num++].Trim();
                    settings.CSSBodyContainer = strArray[num++].Trim();
                    settings.CSSBodyFooter = strArray[num++].Trim();
                    settings.CSSBodyHeader = strArray[num++].Trim();
                    settings.CSSCell = strArray[num++].Trim();
                    settings.CSSCellPadding = strArray[num++].Trim();
                    settings.CSSCellTemporaryAdded = strArray[num++].Trim();
                    settings.CSSCellTemporaryDeleted = strArray[num++].Trim();
                    settings.CSSCellTemporaryEdited = strArray[num++].Trim();
                    settings.CSSColumnHeader = strArray[num++].Trim();
                    settings.CSSColumnHeaderArrow = strArray[num++].Trim();
                    settings.CSSColumnHeaderArrowCenter = strArray[num++].Trim();
                    settings.CSSColumnHeaderArrowRight = strArray[num++].Trim();
                    settings.CSSContainer = strArray[num++].Trim();
                    settings.CSSEditControl = strArray[num++].Trim();
                    settings.CSSExportCellStyle = strArray[num++].Trim();
                    settings.CSSExportHeaderCellStyle = strArray[num++].Trim();
                    settings.CSSExportTableStyle = strArray[num++].Trim();
                    settings.CSSFilterCell = strArray[num++].Trim();
                    settings.CSSFilterCriteria = strArray[num++].Trim();
                    settings.CSSFilterCriteriaHover = strArray[num++].Trim();
                    settings.CSSFilterCriteriasButton = strArray[num++].Trim();
                    settings.CSSFilterCriteriasContainer = strArray[num++].Trim();
                    settings.CSSFilterCriteriaTextbox = strArray[num++].Trim();
                    settings.CSSFilterFirstCell = strArray[num++].Trim();
                    settings.CSSFilterScrollingSpacer = strArray[num++].Trim();
                    settings.CSSFirstCell = strArray[num++].Trim();
                    settings.CSSFolderImages = strArray[num++].Trim();
                    settings.CSSFooter = strArray[num++].Trim();
                    settings.CSSFooterPageNavContainer = strArray[num++].Trim();
                    settings.CSSFooterRecordsPages = strArray[num++].Trim();
                    settings.CSSGroupDraggingColumn = strArray[num++].Trim();
                    settings.CSSGroupingArea = strArray[num++].Trim();
                    settings.CSSGroupingAreaBottomArrow = strArray[num++].Trim();
                    settings.CSSGroupingAreaColumn = strArray[num++].Trim();
                    settings.CSSGroupingAreaColumnContent = strArray[num++].Trim();
                    settings.CSSGroupingAreaColumnHighlightedWhenDragging = strArray[num++].Trim();
                    settings.CSSGroupingAreaColumnSpacer = strArray[num++].Trim();
                    settings.CSSGroupingAreaDefaultColumn = strArray[num++].Trim();
                    settings.CSSGroupingAreaTopArrow = strArray[num++].Trim();
                    settings.CSSHeader = strArray[num++].Trim();
                    settings.CSSHeaderColumnHighlightedWhenGrouping = strArray[num++].Trim();
                    settings.CSSHeaderContainer = strArray[num++].Trim();
                    settings.CSSHeaderFirstCell = strArray[num++].Trim();
                    settings.CSSLoadingMessage = strArray[num++].Trim();
                    settings.CSSNavigationImage = strArray[num++].Trim();
                    settings.CSSNavigationLink = strArray[num++].Trim();
                    settings.CSSNavigationLinkHover = strArray[num++].Trim();
                    settings.CSSNavigationSeparator = strArray[num++].Trim();
                    settings.CSSNavigationText = strArray[num++].Trim();
                    settings.CSSNoRecordsMessage = strArray[num++].Trim();
                    settings.CSSPageSizeSelector = strArray[num++].Trim();
                    settings.CSSPageSizeText = strArray[num++].Trim();
                    settings.CSSRecord = strArray[num++].Trim();
                    settings.CSSRecordAlternate = strArray[num++].Trim();
                    settings.CSSRecordGroupHeader = strArray[num++].Trim();
                    settings.CSSRecordGroupHeaderButton = strArray[num++].Trim();
                    settings.CSSRecordGroupHeaderCell = strArray[num++].Trim();
                    settings.CSSRecordHover = strArray[num++].Trim();
                    settings.CSSRecordSelected = strArray[num++].Trim();
                    settings.CSSResizeLines = strArray[num++].Trim();
                    settings.CSSResizingTooltip = strArray[num++].Trim();
                    settings.CSSRowEditTemplate = strArray[num++].Trim();
                    settings.CSSScrollingSpacer = strArray[num++].Trim();
                    settings.CSSSelectionArea = strArray[num++].Trim();
                    return settings;
                }
                catch (Exception exception1)
                {
                    if (exception1 != null)
                    {
                    }
                }
            }
            return base.ConvertFrom(context, culture, value);
        }

        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                return "";
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }

        public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
        {
            return new GridCssSettings { 
                CSSActionLink = propertyValues["CSSActionLink"].ToString(), CSSActionLinkFooter = propertyValues["CSSActionLinkFooter"].ToString(), CSSBody = propertyValues["CSSBody"].ToString(), CSSBodyContainer = propertyValues["CSSBodyContainer"].ToString(), CSSBodyFooter = propertyValues["CSSBodyFooter"].ToString(), CSSBodyHeader = propertyValues["CSSBodyHeader"].ToString(), CSSCell = propertyValues["CSSCell"].ToString(), CSSCellPadding = propertyValues["CSSCellPadding"].ToString(), CSSCellTemporaryAdded = propertyValues["CSSCellTemporaryAdded"].ToString(), CSSCellTemporaryDeleted = propertyValues["CSSCellTemporaryDeleted"].ToString(), CSSCellTemporaryEdited = propertyValues["CSSCellTemporaryEdited"].ToString(), CSSColumnHeader = propertyValues["CSSColumnHeader"].ToString(), CSSColumnHeaderArrow = propertyValues["CSSColumnHeaderArrow"].ToString(), CSSColumnHeaderArrowCenter = propertyValues["CSSColumnHeaderArrowCenter"].ToString(), CSSColumnHeaderArrowRight = propertyValues["CSSColumnHeaderArrowRight"].ToString(), CSSContainer = propertyValues["CSSContainer"].ToString(), 
                CSSEditControl = propertyValues["CSSEditControl"].ToString(), CSSExportCellStyle = propertyValues["CSSExportCellStyle"].ToString(), CSSExportHeaderCellStyle = propertyValues["CSSExportHeaderCellStyle"].ToString(), CSSExportTableStyle = propertyValues["CSSExportTableStyle"].ToString(), CSSFilterCell = propertyValues["CSSFilterCell"].ToString(), CSSFilterCriteria = propertyValues["CSSFilterCriteria"].ToString(), CSSFilterCriteriaHover = propertyValues["CSSFilterCriteriaHover"].ToString(), CSSFilterCriteriasButton = propertyValues["CSSFilterCriteriasButton"].ToString(), CSSFilterCriteriasContainer = propertyValues["CSSFilterCriteriasContainer"].ToString(), CSSFilterCriteriaTextbox = propertyValues["CSSFilterCriteriaTextbox"].ToString(), CSSFilterFirstCell = propertyValues["CSSFilterFirstCell"].ToString(), CSSFilterScrollingSpacer = propertyValues["CSSFilterScrollingSpacer"].ToString(), CSSFirstCell = propertyValues["CSSFirstCell"].ToString(), CSSFolderImages = propertyValues["CSSFolderImages"].ToString(), CSSFooter = propertyValues["CSSFooter"].ToString(), CSSFooterPageNavContainer = propertyValues["CSSFooterPageNavContainer"].ToString(), 
                CSSFooterRecordsPages = propertyValues["CSSFooterRecordsPages"].ToString(), CSSGroupDraggingColumn = propertyValues["CSSGroupDraggingColumn"].ToString(), CSSGroupingArea = propertyValues["CSSGroupingArea"].ToString(), CSSGroupingAreaBottomArrow = propertyValues["CSSGroupingAreaBottomArrow"].ToString(), CSSGroupingAreaColumn = propertyValues["CSSGroupingAreaColumn"].ToString(), CSSGroupingAreaColumnContent = propertyValues["CSSGroupingAreaColumnContent"].ToString(), CSSGroupingAreaColumnHighlightedWhenDragging = propertyValues["CSSGroupingAreaColumnHighlightedWhenDragging"].ToString(), CSSGroupingAreaColumnSpacer = propertyValues["CSSGroupingAreaColumnSpacer"].ToString(), CSSGroupingAreaDefaultColumn = propertyValues["CSSGroupingAreaDefaultColumn"].ToString(), CSSGroupingAreaTopArrow = propertyValues["CSSGroupingAreaTopArrow"].ToString(), CSSHeader = propertyValues["CSSHeader"].ToString(), CSSHeaderColumnHighlightedWhenGrouping = propertyValues["CSSHeaderColumnHighlightedWhenGrouping"].ToString(), CSSHeaderContainer = propertyValues["CSSHeaderContainer"].ToString(), CSSHeaderFirstCell = propertyValues["CSSHeaderFirstCell"].ToString(), CSSLoadingMessage = propertyValues["CSSLoadingMessage"].ToString(), CSSNavigationImage = propertyValues["CSSNavigationImage"].ToString(), 
                CSSNavigationLink = propertyValues["CSSNavigationLink"].ToString(), CSSNavigationLinkHover = propertyValues["CSSNavigationLinkHover"].ToString(), CSSNavigationSeparator = propertyValues["CSSNavigationSeparator"].ToString(), CSSNavigationText = propertyValues["CSSNavigationText"].ToString(), CSSNoRecordsMessage = propertyValues["CSSNoRecordsMessage"].ToString(), CSSPageSizeSelector = propertyValues["CSSPageSizeSelector"].ToString(), CSSPageSizeText = propertyValues["CSSPageSizeText"].ToString(), CSSRecord = propertyValues["CSSRecord"].ToString(), CSSRecordAlternate = propertyValues["CSSRecordAlternate"].ToString(), CSSRecordGroupHeader = propertyValues["CSSRecordGroupHeader"].ToString(), CSSRecordGroupHeaderButton = propertyValues["CSSRecordGroupHeaderButton"].ToString(), CSSRecordGroupHeaderCell = propertyValues["CSSRecordGroupHeaderCell"].ToString(), CSSRecordHover = propertyValues["CSSRecordHover"].ToString(), CSSRecordSelected = propertyValues["CSSRecordSelected"].ToString(), CSSResizeLines = propertyValues["CSSResizeLines"].ToString(), CSSResizingTooltip = propertyValues["CSSResizingTooltip"].ToString(), 
                CSSRowEditTemplate = propertyValues["CSSRowEditTemplate"].ToString(), CSSScrollingSpacer = propertyValues["CSSScrollingSpacer"].ToString(), CSSSelectionArea = propertyValues["CSSSelectionArea"].ToString()
             };
        }

        public override bool GetCreateInstanceSupported(ITypeDescriptorContext context)
        {
            return true;
        }
    }
}

